/**
 * 去除字符串两端空格
 * @returns
 */
String.prototype.trim = function(){  
	return this.replace(/(^\s*)|(\s*$)/g, "");  
};

/**
 * 字符串真实长度
 * @returns
 */
String.prototype.getBytes = function() {    
    var cArr = this.match(/[^\x00-\xff]/ig);    
    return this.length + (cArr == null ? 0 : cArr.length);    
};

String.prototype.noBlank = function() {    
	if (this !== null && this !== undefined && this !== '') { 
		return true;
	} 
	return false;
};


/**公共ajax 函数
 * @param url
 * @param data
 * @param callback
 * @param handlerror
 * @returns {String}
 */
function ajaxData(url, data, callback,handlerror){
	var result = "";
	$.ajax({
		type : "post",
		url : encodeURI(encodeURI(url)),
		data : data,
		dataType : "html",
		contentType: "application/x-www-form-urlencoded; charset=UTF-8",
		async: true,
		cache: false,
		success:function(json){
			if(callback!=null){
				callback(json);
			}
			result = json;
		},
		error:function(xhr, ajaxOptions, thrownError){
			if(handlerror!=null){
				handlerror(xhr, ajaxOptions, thrownError);
			}
		}
	});
	return result;
}	
function errorHandle(option){
	Metronic.unblockUI(option.blockid);
	if(!option.msg){
		option.msg = "系统繁忙，请稍后再试！";
	}
	Metronic.alert({
		container:option.container,
        message: option.msg,
        type:"danger"
	})
}
function confirmModal(type,msg){
	$("#confirm-modal").modal({backdrop: 'static', keyboard: false});
	$('#confirm-modal .modal-body').text(msg);
	$('#confirm-modal').modal(type);
}
function logout(){
	confirmModal('show','是否退出？');
	$('#confirm-modal .dosure').unbind('click').on('click',function(e){
		window.location.href="/admin/login/out";
	});
}
function getRemote(url,data){
	url = url+"?t=get";
	$.get(url,data,function(datas,status){
		$('#config-modal .modal-content').html('');  
		$('#config-modal').modal({backdrop: 'static', keyboard: false});
		$('#config-modal .modal-content').html(datas);  
	});
}
function putQueryData(formid,object){
	var qdata = $(formid).serializeArray();
	for(var x=0;x<object.length;x++){
		/*if(object[x].data=='sEcho'||object[x].data=='iDisplayStart'||object[x].data=='iDisplayLength'){
			continue;
		}else{
			object.splice(x,1);
			x--;//删除下标为x的元素后，该位置又被新的元素所占据，所以要重新检测该位置
		}*/
		object.splice(x,1);
	}
	 if(qdata!=null){
		 for(var i = 0;i<qdata.length;i++){
			 object.push( qdata[i] );
		 }
	 }
}
function login(){
	sessionStorage.clear();
	window.top.location="/admin/login";  
}
